package com.grudesign.stutrip.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.util.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.grudesign.stutrip.common.ReturnInfo;
import com.grudesign.stutrip.entity.Po.StutriprecordsPo;
import com.grudesign.stutrip.entity.Vo.frontRecordVo;
import com.grudesign.stutrip.mapper.StutriprecordsMapper;
import com.grudesign.stutrip.service.StutriprecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 研学游记表 服务实现类
 * </p>
 *
 * @author wx
 * @since 2022-05-09
 */
@Service
public class StutriprecordsServiceImpl extends ServiceImpl<StutriprecordsMapper, StutriprecordsPo> implements StutriprecordsService {

    @Resource
    private StutriprecordsMapper stutriprecordsMapper;
    @Override
    public Object getStuTrips(String cur, String li) {
        Page<StutriprecordsPo> page = new Page<>(Long.parseLong(cur),Long.parseLong(li));
        Page<StutriprecordsPo> stutriprecordsPoPage = baseMapper.selectPage(page, Wrappers.emptyWrapper());
        return new ReturnInfo("200","ok").data("stuTripInfo",stutriprecordsPoPage);
    }

    @Override
    public Object getRecords() {
        List<frontRecordVo> records = stutriprecordsMapper.getRecords();
        return new ReturnInfo("200","ok").data("record",records);
    }

    @Override
    public Object getStutrip(String cur, String li, StutriprecordsPo po) {
        if(null==po){
            return new ReturnInfo("200","ok").data("record",getRecords());
        }
        String title = po.getTitle();
        if(StringUtils.hasText(title)) {
            String title2 = "%" + title + "%";
            po.setTitle(title2);
        }
        Page<frontRecordVo> recordVoPage = new Page<>(Long.parseLong(cur),Long.parseLong(li));
        IPage<frontRecordVo> queryRecords = stutriprecordsMapper.getQueryRecords(recordVoPage, po);

        return new ReturnInfo("200","ok").data("records",queryRecords);
    }
}
